import allure
import pytest
from selenium import webdriver


@pytest.fixture(scope="module")
def driver():
    global driver
    url = 'http://192.168.1.155/ecshop/admin'
    driver = webdriver.Edge()
    driver.get(url)
    driver.maximize_window()
    yield driver
    driver.quit()

# 钩子函数，获取结果
@pytest.hookimpl(hookwrapper=True,tryfirst=True)
def pytest_runtest_makereport(item,call):
# 获取钩子函数的结果
    out = yield
    # 获取测试报告
    report = out.get_result()
    # 脚本执行失败，截图
    if report.when == 'call' and report.outcome == "failed":
        # 把截图保存到测试报告中
        allure.attach(driver.get_screenshot_as_png(),"失败截图",allure.attachment_type.PNG)













